package com.handpay.zztong.hp.swiper.model.swiperstatus;

import android.content.DialogInterface;

import com.handpay.framework.fastjson.FastJsonHelper;
import com.handpay.zztong.hp.base.activity.ZZTongActivity;
import com.handpay.zztong.hp.base.callback.BusinessEngineListener;
import com.handpay.zztong.hp.base.model.base.BaseModel;
import com.handpay.zztong.hp.config.HttpUrlConstant;
import com.handpay.zztong.hp.utils.AccountUtils;

import java.util.Hashtable;

/**
 * Created by lyang on 2017/3/24.
 */

public class SwiperStatusModel extends BaseModel{

    private BusinessEngineListener mBusinessEngineListener;


    public boolean doSwiperStatusPost(ZZTongActivity activity, Hashtable<String, String> params, BusinessEngineListener listener) {
        mBusinessEngineListener = listener;
        return doPost(activity, HttpUrlConstant.Do_GetSwiperStatus, params, true, false);
    }
    @Override
    public boolean netResponse(String action, byte[] data) {
        DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                AccountUtils.removeRMSPWDData();
                dialog.dismiss();
            }
        };
        boolean bResult = super.netResponse(action, data, listener);

        if (bResult) {
            return true;
        }
        if (action.equals(HttpUrlConstant.Do_GetSwiperStatus)) {
            SwiperStatusBean bean = null;
            if (data_type == DATA_TYPE.DATA_TYPE_JSON) {
                try {
                    String result = new String(data, "UTF-8");
                    bean = FastJsonHelper.getObject(result, SwiperStatusBean.class);

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (mBusinessEngineListener != null) {
                mBusinessEngineListener.callbackBusinessResponse(bean);
            }
        }
        return true;
    }
}
